package controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import entity.Userinfo;
import service.serviceimpl.ServiceUserImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @Author wuchao66
 * @Date 2023/5/23 10:25
 * @PackageName:${PACKAGE_NAME}
 * @ClassName: ${NAME}
 * @Description: TODO
 * @Param
 * @Version 1.0
 */
@WebServlet(name = "ServletPage",urlPatterns = "/ServletPage")
public class ServletPage extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();//文件流

        out.flush();
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();//文件流
        //导入工具类型
        PageHelper.startPage(1,3);
        //查找所有
        ServiceUserImpl serviceUser = new ServiceUserImpl();
        List<Userinfo> userinfos =
                serviceUser.executeQuery("select * from userinfo limit 3,3");
        //所有一切分页的东西都给你算好了
        PageInfo<Userinfo> userinfoPageInfo = new PageInfo<>(userinfos);
        request.setAttribute("pageinfo",userinfoPageInfo);
        request.getRequestDispatcher("/demo7/page154.jsp").forward(request,response);

        out.flush();
        out.close();
    }
}
